package core

import (
	"gin-admin/common/dto/response"
	"gin-admin/global"

	"gorm.io/gorm"
)

func HandelError(result *gorm.DB) *response.ServiceError {
	if result.Error != nil && result.Error != gorm.ErrRecordNotFound {
		global.GA_LOGGER.Sugar().Errorw("数据库操作失败", "error", result.Error.Error())
		return response.WrapError(response.FailedCode, response.GetStatusCode(response.FailedCode).Message)
	}
	return nil
}
